/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.Collection;
/*     */ import java.util.HashMap;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ModifyAdminSavedSearches
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   public boolean domainAuthSufficient(Map context)
/*     */   {
/*  41 */     return true;
/*     */   }
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context) throws ServiceException {
/*  45 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  46 */     Account acct = getRequestedAccount(zsc);
/*     */     
/*  48 */     checkAccountRight(zsc, acct, Rights.Admin.R_setAdminSavedSearch);
/*     */     
/*  50 */     Element response = zsc.createElement(AdminConstants.MODIFY_ADMIN_SAVED_SEARCHES_RESPONSE);
/*     */     
/*  52 */     HashMap<String, String> searches = null;
/*  53 */     for (Iterator it = request.elementIterator("search"); it.hasNext();) {
/*  54 */       if (searches == null)
/*  55 */         searches = new HashMap();
/*  56 */       Element e = (Element)it.next();
/*  57 */       String name = e.getAttribute("name");
/*  58 */       String query = e.getText();
/*  59 */       if ((name != null) && (name.length() != 0)) {
/*  60 */         searches.put(name, query);
/*     */       } else {
/*  62 */         ZimbraLog.account.warn("ModifyAdminSavedSearches: empty search name ignored");
/*     */       }
/*     */     }
/*  65 */     handle(acct, response, searches);
/*  66 */     return response;
/*     */   }
/*     */   
/*     */   public void handle(Account acct, Element response, HashMap<String, String> modSearches) throws ServiceException {
/*  70 */     String[] searches = acct.getMultiAttr("zimbraAdminSavedSearches");
/*  71 */     Map<String, GetAdminSavedSearches.AdminSearch> curSearches = new HashMap();
/*  72 */     for (int i = 0; i < searches.length; i++) {
/*  73 */       GetAdminSavedSearches.AdminSearch as = GetAdminSavedSearches.AdminSearch.parse(searches[i]);
/*  74 */       curSearches.put(as.getName(), as);
/*     */     }
/*     */     
/*  77 */     for (Iterator it = modSearches.entrySet().iterator(); it.hasNext();) {
/*  78 */       Map.Entry entry = (Map.Entry)it.next();
/*  79 */       String name = (String)entry.getKey();
/*  80 */       String query = (String)entry.getValue();
/*  81 */       GetAdminSavedSearches.AdminSearch mod = new GetAdminSavedSearches.AdminSearch(name, query);
/*  82 */       if (curSearches.containsKey(name)) {
/*  83 */         if (query.length() == 0) {
/*  84 */           curSearches.remove(name);
/*     */         } else
/*  86 */           curSearches.put(name, mod);
/*     */       } else {
/*  88 */         if (query.length() == 0) {
/*  89 */           throw ServiceException.INVALID_REQUEST("query for " + name + " is empty", null);
/*     */         }
/*  91 */         curSearches.put(name, mod);
/*     */       }
/*     */     }
/*     */     
/*  95 */     String[] mods = new String[curSearches.size()];
/*  96 */     int i = 0;
/*  97 */     for (Iterator it = curSearches.values().iterator(); it.hasNext();) {
/*  98 */       GetAdminSavedSearches.AdminSearch m = (GetAdminSavedSearches.AdminSearch)it.next();
/*  99 */       mods[(i++)] = m.encode();
/*     */     }
/*     */     
/* 102 */     Provisioning prov = Provisioning.getInstance();
/* 103 */     Map<String, String[]> modmap = new HashMap();
/* 104 */     modmap.put("zimbraAdminSavedSearches", mods);
/* 105 */     prov.modifyAttrs(acct, modmap);
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 110 */     relatedRights.add(Rights.Admin.R_setAdminSavedSearch);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/ModifyAdminSavedSearches.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */